package gof_003_行为型_Behavioral.gof_004_策略_Strategy.gof_002_Strategy;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {

    //生成学生列表
    public static List<Student> generateStudentList() {
        List<Student> studentList = Stream.of(
                new Student("赵18", 18),
                new Student("钱19", 19),
                new Student("孙20", 20),
                new Student("李21", 21),
                new Student("周22", 22),
                new Student("吴23", 23),
                new Student("郑24", 24),
                new Student("王25", 25)
        ).collect(Collectors.toList());
        return studentList;
    }

    //展示学生列表
    public static void showStudentList(List<Student> studentList) {
        System.out.println("======= 学生列表 =======");
        int index = 0;
        for (Student student : studentList) {
            System.out.println(++index + ".  姓名:" + student.getName() + "\t年龄:" + student.getAge());
        }
    }


    public static void main(String[] args) {
        List<Student> studentList = generateStudentList();
        showStudentList(studentList);

        //策略1
        FilterStudent strategy_1 = new FilterStudent(new Strategy_1());
        List<Student> list1 = strategy_1.filter(studentList);
        System.out.println("\n策略1: 年龄大于20岁");
        showStudentList(list1);

        //策略2
        FilterStudent strategy_2 = new FilterStudent(new Strategy_2());
        List<Student> list2 = strategy_2.filter(studentList);
        System.out.println("\n策略2: 年龄大于20并且小于等于23");
        showStudentList(list2);

        //策略3
        FilterStudent strategy_3 = new FilterStudent(new Strategy_3());
        List<Student> list3 = strategy_3.filter(studentList);
        System.out.println("\n策略3: 年龄小于等于24并且姓是赵钱中的一个");
        showStudentList(list3);

    }
}
